home *** CD-ROM | disk | FTP | other *** search
- /**\
- |**| =====================================================================
- |**|
- |**| viewPort Mania.c
- |**|
- |**| gxViewPort Mania creates a window and attaches 6 childViewPorts to
- |**| the parent gxViewPort of the window. We create a textShape and attach
- |**| this gxShape to all of the childViewPorts. This will allow the
- |**| textShape to be drawn into all 6 childViewPorts simultaneously.
- |**| Each of the childViewPorts has different attributes applied, which
- |**| causes the textShape to be drawn in a slightly different manner in
- |**| each of the childViewPorts.
- |**|
- |**| The following list describes the settings of each of the childViewPorts:
- |**|
- |**| childViewPort 1: textShape will be drawn in it's native geometry.
- |**| childViewPort 2: textShape will be scaled by 200% before it is drawn.
- |**| childViewPort 3: textShape will be scaled by 200% and the gxGrayPort
- |**| attribute will be applied to the childViewPort before
- |**| the textShape is drawn
- |**| childViewPort 4: textShape will be scaled by 300% in the x direction
- |**| childViewPort 5: textShape will be scaled by 300% in the y direction
- |**| childViewPort 6: textShape will be drawn through an Round Dot gxHalftone
- |**|
- |**| All of the previous effects for each childViewPort will be setup
- |**| in the AdjustChildViewPortInfo function.
- |**|
- |**|
- |**| QuickDraw GX Libraries Used:
- |**| "color library.c", "font library.c", "graphics debug library.c",
- |**| "shape library.c", and "transform library.c".
- |**|
- |**| Change History:
- |**| 3/90 ??? New
- |**| 4/96 cnn Changed fixed to Fixed.
- |**|
- |**| ©1990-1996 Apple Computer, Inc.
- |**| All rights reserved.
- |**|
- |**| =====================================================================
- \**/
-
-
- #include "graphics shell.h"
-
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| ENUMS
- |**| ---------------------------------------------------------------------
- \**/
- enum { kNumberOfChildViewPorts = 6,
- kNumberOfTextShapesToBeDrawn = 17,
-
- kSpacingBetweenChildViewPorts = 25,
- kSpacingForTextInfoBetweenChildViewPorts = 15,
- kWidthOfAChildViewPort = 150,
-
- kTextShapeTextSize = 36,
- kTextShapeStartingHLocation = 24,
- kTextShapeStartingVLocation = 92 };
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| GLOBALS
- |**| ---------------------------------------------------------------------
- \**/
- // If gDebugging = TRUE, graphics library errors and notices will be posted. This
- // functionality will only work with the "debugging" version of QuickDraw GX.
- // If the debugging version is not installed, nothing bad will happen, but these
- // functions will not work.
-
- Boolean gDebugging = true;
-
- // Set "gGiveMeValidation" to TRUE if you want receive run-time validation.
-
- Boolean gGiveMeValidation = true;
-
-
- // gGraphicsHeapSize sets the size of the graphics heap created by calling the
- // GXNewGraphicsClient routine in main () within QuickDraw GX shell.c. You can determine
- // the amount of graphics heap required by using GraphicsBug.
-
- long gGraphicsHeapSize = 75;
-
-
-
- gxShape gTextShape;
- gxColor gTextColor;
-
- //
- // Contains the list of all created viewPorts. You need this list to enable the application to attach
- // the gTextShape to all of the child viewPorts attached to the window.
- //
- gxViewPort gChildViewPortList[kNumberOfChildViewPorts];
- short gTotalNumberOfTextShapesDrawn,
- gDegreesOfRotation;
- Fixed x,y;
-
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| PROTOTYPES
- |**| ---------------------------------------------------------------------
- \**/
-
- // funtions required by shell
-
- void DoInitialization (WindowPtr wind);
- void DoDraw (WindowPtr wind);
- void DoDispose (WindowPtr wind);
- void DoClick (gxPoint orgMouseLoc, WindowPtr theWindow );
- void DoIdle (WindowPtr wind);
-
- // private functions
-
- void AdjustChildViewPortInfo (gxViewPort temporaryChildViewPort, short childViewPortCounter);
- void DrawInfo (void);
-
-
-
- /*------ AdjustChildViewPortInfo ------------------------------------------------------------------------*/
-
- void AdjustChildViewPortInfo (gxViewPort temporaryChildViewPort, short childViewPortCounter)
- {
- gxMapping childViewPortMapping;
- gxShape childViewPortFrame;
- gxRectangle childViewPortFrameBounds;
- Fixed x,y;
- gxHalftone theHalfTone;
-
- // NOTE: the childViewPortCounter is 0 based
-
- switch (childViewPortCounter){
-
- //
- // childViewPort #2 : get the gxMapping of the childViewPort, and scale it by 200%
- //
- case 1:
- GXGetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
- childViewPortFrame = GXGetViewPortClip(temporaryChildViewPort);
-
- GXGetShapeBounds(childViewPortFrame, 0L, &childViewPortFrameBounds);
-
- x = childViewPortFrameBounds.left + childViewPortFrameBounds.right >> 1;
- y = childViewPortFrameBounds.top + childViewPortFrameBounds.bottom >> 1;
- ScaleMapping(&childViewPortMapping, ff(2), ff(2), x, y);
-
- GXSetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
-
- GXDisposeShape(childViewPortFrame);
- break;
-
-
- //
- // childViewPort #3 : set the childViewPort with a dither level of 4 and set the gxGrayPort attribute.
- // get the gxMapping of the childViewPort, and scale it by 200%
- //
- case 2:
- GXSetViewPortAttributes(temporaryChildViewPort, gxGrayPort);
- GXSetViewPortDither (temporaryChildViewPort, 4);
-
- GXGetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
- childViewPortFrame = GXGetViewPortClip(temporaryChildViewPort);
-
- GXGetShapeBounds(childViewPortFrame, 0L, &childViewPortFrameBounds);
-
- x = childViewPortFrameBounds.left + childViewPortFrameBounds.right >> 1;
- y = childViewPortFrameBounds.top + childViewPortFrameBounds.bottom >> 1;
- ScaleMapping(&childViewPortMapping, ff(2), ff(2), x, y);
-
- GXSetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
-
- GXDisposeShape(childViewPortFrame);
- break;
-
- //
- // childViewPort #4 : set the childViewPort with a dither level of 4. get the gxMapping of the childViewPort,
- // and scale it by 300% in the x (vertical) direction.
- //
- case 3:
- GXSetViewPortDither (temporaryChildViewPort, 4);
-
- GXGetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
-
- childViewPortFrame = GXGetViewPortClip(temporaryChildViewPort);
-
- GXGetShapeBounds(childViewPortFrame, 0L, &childViewPortFrameBounds);
-
- x = childViewPortFrameBounds.left + childViewPortFrameBounds.right >> 1;
- y = childViewPortFrameBounds.top + childViewPortFrameBounds.bottom >> 1;
- ScaleMapping(&childViewPortMapping, ff(1), ff(3), x, y);
-
- GXSetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
-
- GXDisposeShape(childViewPortFrame);
- break;
-
- //
- // childViewPort #5 : set the childViewPort with a dither level of 4. get the gxMapping of the childViewPort,
- // and scale it by 300% in the y (horizontal) direction.
- //
- case 4:
- GXSetViewPortDither (temporaryChildViewPort, 4);
- GXGetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
-
- childViewPortFrame = GXGetViewPortClip(temporaryChildViewPort);
-
- GXGetShapeBounds(childViewPortFrame, 0L, &childViewPortFrameBounds);
-
- x = childViewPortFrameBounds.left + childViewPortFrameBounds.right >> 1;
- y = childViewPortFrameBounds.top + childViewPortFrameBounds.bottom >> 1;
- ScaleMapping(&childViewPortMapping, ff(3), ff(1), x, y);
-
- GXSetViewPortMapping(temporaryChildViewPort, &childViewPortMapping);
-
- GXDisposeShape(childViewPortFrame);
- break;
-
- //
- // childViewPort #6 : set the childViewPort with an gxRoundDot gxHalftone in gxHsvSpace
- //
- case 5:
- theHalfTone.angle = ff(6);
- theHalfTone.frequency = ff(24);
- theHalfTone.method = gxRoundDot;
- theHalfTone.tinting = gxComponent2Tint;
-
- theHalfTone.tintSpace = gxCMYKSpace;
- theHalfTone.backgroundColor.space = gxHSVSpace;
- theHalfTone.backgroundColor.profile = nil;
- theHalfTone.backgroundColor.element.hsv.value = 0xFFFF;
- theHalfTone.backgroundColor.element.hsv.saturation = 0xCCCD;
- theHalfTone.backgroundColor.element.hsv.hue = 0x8000;
-
- theHalfTone.dotColor.space = gxHSVSpace;
- theHalfTone.dotColor.profile = nil;
- theHalfTone.dotColor.element.hsv.value = 0xFFFF;
- theHalfTone.dotColor.element.hsv.saturation = 0xAD1C;
- theHalfTone.dotColor.element.hsv.hue = 0xE4F9;
-
- GXSetViewPortHalftone(temporaryChildViewPort, &theHalfTone);
- break;
-
- default: break;
- }
- }
-
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization (WindowPtr wind)
- {
- gxShape childViewPortShape;
- gxRectangle textBoundsShape;
- gxViewPort windowViewPortParent, temporaryChildViewPort;
- short childViewPortCounter;
- Fixed childViewPortLeftEdge = kSpacingBetweenChildViewPorts, childViewPortTopEdge = kSpacingBetweenChildViewPorts,
- childViewPortRightEdge = kWidthOfAChildViewPort + kSpacingBetweenChildViewPorts,
- childViewPortBottomEdge = kWidthOfAChildViewPort + kSpacingBetweenChildViewPorts;
-
- gTotalNumberOfTextShapesDrawn = 0;
- gDegreesOfRotation = 22;
-
- InitCommonColors ();
-
- //
- // Get the gxViewPort parent for the current window. We need this gxViewPort ot allow us to attach
- // all of the childViewPorts to.
- //
- windowViewPortParent = GXGetWindowViewPort(wind);
-
- //
- // Create the childViewPort and attach it to the parentViewPort of the current window
- //
- for (childViewPortCounter = 0; childViewPortCounter < kNumberOfChildViewPorts; childViewPortCounter++)
- {
- gxRectangle viewBox;
-
- viewBox.left = ff(childViewPortLeftEdge);
- viewBox.top = ff(childViewPortTopEdge);
- viewBox.right = ff(childViewPortRightEdge);
- viewBox.bottom = ff(childViewPortBottomEdge);
-
- childViewPortShape = GXNewRectangle(&viewBox);
-
- temporaryChildViewPort = GXNewViewPort(gxScreenViewDevices);
-
- //
- // Set the "new" childViewPort to the parentViewPort; Also, set it's clip gxShape and gxMapping
- //
- GXSetViewPortParent(temporaryChildViewPort, windowViewPortParent);
- GXSetViewPortClip(temporaryChildViewPort, childViewPortShape);
- GXSetViewPortMapping(temporaryChildViewPort, nil);
-
- //
- // Change the current childViewPort's attributes for aome excitement(?)
- //
- AdjustChildViewPortInfo (temporaryChildViewPort, childViewPortCounter);
-
- gChildViewPortList[childViewPortCounter] = temporaryChildViewPort;
-
- childViewPortLeftEdge = childViewPortRightEdge + kSpacingBetweenChildViewPorts;
- childViewPortRightEdge = childViewPortLeftEdge + kWidthOfAChildViewPort;
-
- if (childViewPortCounter == 2) {
- childViewPortLeftEdge = kSpacingBetweenChildViewPorts;
- childViewPortTopEdge = childViewPortBottomEdge + kSpacingBetweenChildViewPorts + kSpacingForTextInfoBetweenChildViewPorts;
- childViewPortRightEdge = kWidthOfAChildViewPort + kSpacingBetweenChildViewPorts;
- childViewPortBottomEdge = childViewPortTopEdge + kWidthOfAChildViewPort;
- }
-
- GXDisposeShape(childViewPortShape);
- }
-
-
- //
- // Set up an HSV gxColor space to run the text through...
- //
- gTextColor.space = gxHSVSpace;
- gTextColor.profile = nil;
- gTextColor.element.hsv.hue = 0xFFFF;
- gTextColor.element.hsv.value = 0xFFFF;
- gTextColor.element.hsv.saturation = 0xFFFF;
-
- //
- // Set the gTextShape's: text string content, the gxFont, and size
- //
- gTextShape = GXNewText(6,(unsigned char*)"Moof!!", nil);
- SetShapeCommonFont(gTextShape, timesFont);
- GXSetShapeTextSize(gTextShape, ff(kTextShapeTextSize));
-
- //
- // Move the gTextShape into the middle of the childViewPort, and attach the gxShape to all of the childViewPorts in the window.
- //
- GXMoveShapeTo(gTextShape, ff(kTextShapeStartingHLocation), ff(kTextShapeStartingVLocation));
- GXSetShapeViewPorts(gTextShape, kNumberOfChildViewPorts, gChildViewPortList);
-
- //
- // Get the bounds of the gTextShape, and the location of the center of gTextShape. x & y will be used to in the
- // GXRotateShape call in the DoDraw functions to make the text rotate around it's center.
- //
- GXGetShapeBounds(gTextShape, 0L, &textBoundsShape);
- x = textBoundsShape.left + textBoundsShape.right >> 1;
- y = textBoundsShape.top + textBoundsShape.bottom >> 1;
-
- GXSetShapeAttributes (gTextShape, gxMapTransformShape | GXGetShapeAttributes(gTextShape));
- }
-
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw (WindowPtr wind)
- {
- short drawViewPortFrameLoop;
-
- if (gTotalNumberOfTextShapesDrawn == 0 || gTotalNumberOfTextShapesDrawn == kNumberOfTextShapesToBeDrawn) {
-
- //
- // Get the frame gxShape from each child gxViewPort, and draw the frame.
- //
- for (drawViewPortFrameLoop = 0; drawViewPortFrameLoop < kNumberOfChildViewPorts; drawViewPortFrameLoop++)
- {
- gxShape childViewPortFrame;
-
- childViewPortFrame = GXGetViewPortClip(gChildViewPortList [drawViewPortFrameLoop]);
-
- //
- // Let's erase the contents of the this childViewPort
- //
- SetShapeCommonColor (childViewPortFrame,gxWhite);
- GXDrawShape (childViewPortFrame);
-
- //
- // Let's redraw the frame of the current childViewPort. Set the gxShape's fill to be a frame, set the gxColor,
- // set the pen thickness, and set the gxStyle attributes to draw the frame on the outside of the childViewPortFrame
- // gxShape. This prevents the frame from falling a few pixels within the bounds of the childViewPort. **/
- //
- GXSetShapeStyleAttributes(childViewPortFrame, gxOutsideFrameStyle);
- GXSetShapeFill (childViewPortFrame, gxClosedFrameFill);
- SetShapeCommonColor (childViewPortFrame, gxBlack);
- GXSetShapePen(childViewPortFrame, ff(2));
- GXDrawShape (childViewPortFrame);
- GXDisposeShape(childViewPortFrame);
- }
-
- //
- // Draw the text information below each childViewPort
- //
- DrawInfo ();
- }
-
-
- if (gTotalNumberOfTextShapesDrawn == kNumberOfTextShapesToBeDrawn) {
-
- //
- // The text has been rotated 360 degrees. Let's reset the gxShape's gxTransform. By resetting the gxTransform
- // will reset the gxTransform back to the GX default gxTransform (i.e. no rotate).
- //
- // With the call to GXRotateShape below, we have been only effecting the gxShape's gxTransform
- // instead of the gxShape's geometry because we had set the gxMapTransformShape attribute above. When we reset
- // the tranform of our text gxShape, we need to also reset the gxViewPort because the GXResetTransform call
- // also resets the gxViewPort list.
- //
- GXResetTransform(GXGetShapeTransform(gTextShape));
- GXSetShapeViewPorts(gTextShape, kNumberOfChildViewPorts, gChildViewPortList);
-
-
- gDegreesOfRotation = -gDegreesOfRotation;
- gTotalNumberOfTextShapesDrawn = 0;
- }
-
- GXSetShapeColor(gTextShape, &gTextColor);
- GXDrawShape(gTextShape);
-
- gTextColor.element.hsv.hue -= 0x0600;
-
- GXRotateShape(gTextShape, ff(gDegreesOfRotation), x, y);
-
- gTotalNumberOfTextShapesDrawn++;
- }
-
-
-
- /*------ DrawInfo --------------------------------------------------------------------------------------*/
- //
- // This functions draws the text information below each childViewPort.
- //
- void DrawInfo (void)
- {
- gxShape textTitleShape;
- gxPoint textLocation;
-
- //
- // We want to reset various attributes of the text as we move our messages around under the various ViewPort.
- //
- GXIgnoreGraphicsNotice(text_size_already_set);
-
- //
- // Create the textTitleShape, by setting the: Font, size, and starting location...
- //
- textLocation.x = ff(60); textLocation.y = ff(190);
- textTitleShape = GXNewText(14, (unsigned char*)"original Shape", &textLocation);
- SetShapeCommonFont(textTitleShape, timesFont);
- GXSetShapeTextSize(textTitleShape, ff(12));
- GXDrawShape (textTitleShape);
-
- //
- // Change the textTitleShape for the next message...
- //
- textLocation.x = ff(240);
- GXSetText(textTitleShape, 12, (unsigned char*)"200% Scaling", &textLocation);
- GXDrawShape (textTitleShape);
-
-
- textLocation.x = ff(365);
- GXSetText(textTitleShape, 34, (unsigned char*)"200% Scaling with a gray attribute", &textLocation);
- GXDrawShape (textTitleShape);
-
- textLocation.x = ff(17); textLocation.y = ff(380);
- GXSetText(textTitleShape, 31, (unsigned char*)"300% Scaling in the x direction", &textLocation);
- GXDrawShape (textTitleShape);
-
- textLocation.x = ff(195);
- GXSetText(textTitleShape, 31, (unsigned char*)"300% Scaling in the y direction", &textLocation);
- GXDrawShape (textTitleShape);
-
- textLocation.x = ff(370);
- GXSetText(textTitleShape,30, (unsigned char*)"Round Dot Halftone in HSVSpace", &textLocation);
- GXDrawShape (textTitleShape);
-
- GXDisposeShape (textTitleShape);
-
- //
- // We need to balance all of our GXIgnoreGraphicsNotice calls with GXPopGraphicsNotice calls,
- // thereby preventing the notice stack from overflowing.'
- //
- GXPopGraphicsNotice();
- }
-
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose (WindowPtr wind)
- {
- //
- // You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- // form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- // call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- // SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- // can turn notices on in this file by setting gDebugging = TRUE (above).
- //
- GXDisposeShape(gTextShape);
- DisposeCommonColors();
- DisposeWindow(wind);
- }
-
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick (gxPoint orgMouseLoc, WindowPtr theWindow )
- {
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle (WindowPtr wind)
- {
- DoDraw(wind);
- }
-